import router from '@/router'
import store from '@/store'
import { Message } from 'element-ui';
var whiteList = ['/login'];
var typeList = ['/account/add', '/account/list', '/security/add', '/security/list'];
console.log(whiteList);
router.beforeEach((to, from, next) => {
    if (store.getters.token) {
        if (to.path == '/login') {
            next('/home/dashboard');
        }
        else if (typeList.indexOf(to.path) !== -1) {
            if (store.getters.type == 1) {
                next();
            }
            else {

                store.dispatch('QuitAction');
                Message({ message: "您没有权限访问该页面，请切换超级管理员账号登录", type: "warning", offset: 80 })
                next('/login');
            }
        }
        else {
            next();
        }
    }
    else {
        if (whiteList.indexOf(to.path) !== -1) {
            next();
        }
        else {
            next('/login');
        }
    }
})